﻿@using Digital.WCFClient.ConfigService
@using System.Collections.ObjectModel
@using Digital.Common.Mvc.Extensions
@using Digital.Web.Controllers
@using Microsoft.AspNet.Identity
@using Digital.Common.Utilities
@model Digital.WCFClient.ConfigService.SinglePageModel
@{
    ViewBag.Title = "添加单页";
    Layout = "~/Views/Shared/_LayoutDigital.cshtml";
}

@section PageSpecificJavascriptIncludes{
    <link href="../DigitalStyle/css/jquery.gritter.css" rel="stylesheet" />

    <script src="../DigitalStyle/js/jquery.gritter.min.js"></script>
    <script src="../DigitalStyle/js/jquery.autogrow-textarea.js"></script>
    <script src="../DigitalStyle/js/chosen.jquery.min.js"></script>
    <script src="../DigitalStyle/js/jquery.validate.js"></script>
    <script src="../DigitalStyle/js/JqueryToken.js"></script>

    <script src="../DigitalStyle/js/ckeditor/ckeditor.js"></script>
    <script src="../DigitalStyle/js/ckeditor/adapters/jquery.js"></script>
    <script src="../DigitalStyle/js/formvalidator.js"></script>

}
<div class="contentpanel">
    <div class="row">

        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="panel-btns">
                    <a href="" class="panel-close">&times;</a>
                    <a href="" class="minimize">&minus;</a>
                </div>
                <h4 class="panel-title">单独页面添加</h4>
                <p>类似 关于我们、联系我们等页面均属于单独页面，您还可以自由增减相关信息，如：售后服务、企业资质等内容</p>
            </div>

            <div class="panel-body">
                <form class="form" id="firstForm" onsubmit="return false">
                    @Html.AntiForgeryToken()
                    <div class="form-group">
                        <label class="col-sm-1 control-label"><span class="asterisk">*</span> 页面标题</label>
                        <div class="col-sm-6">
                            @*<input id="PageTitle" value="@Model.PageTitle" type="text" placeholder="" class="form-control" required />*@
                            @Html.TextBoxFor(m => m.PageTitle, new { @class = "form-control" })
                            @Html.ValidationMessageFor(m => m.PageTitle, null, new { @class="help-inline"})
                            <span class="help-block">
                                标题信息将便于搜索引擎对该页面的判定，以确定排名
                            </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label"><span class="asterisk">*</span> 关键字</label>
                        <div class="col-sm-6">
                            @*<input id="PageKeyWords" value="@Model.PageKeyWords" type="text" placeholder="" class="form-control" required />*@
                            @Html.TextBoxFor(m => m.PageKeyWords, new { @class = "form-control" })
                            @Html.ValidationMessageFor(m => m.PageKeyWords, null, new { @class="help-inline"})
                            <span class="help-block">
                                关键字信息将用于您的网站优化
                            </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label"><span class="asterisk">*</span> 页面描述</label>
                        <div class="col-sm-6">
                            @*<textarea id="PageDescription" class="form-control" rows="5" required>@Model.PageDescription</textarea>*@
                            @Html.TextAreaFor(m => m.PageDescription, new { @class = "form-control", @rows = "5" })
                            @Html.ValidationMessageFor(m => m.PageDescription, null, new { @class="help-inline"})
                            <span class="help-block">
                                (限100字内)
                            </span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-1 control-label">关联标示</label>
                        <div class="col-sm-6">
                            <div class="col-sm-3">
                                @*<input id="PageRelationFlag" value="@Model.PageRelationFlag" type="text" placeholder="" class="form-control">*@
                                @Html.TextBoxFor(m => m.PageRelationFlag, new { @class = "form-control" })
                                @Html.ValidationMessageFor(m => m.PageRelationFlag, null, new { @class="help-inline"})
                            </div>
                            <div class="col-sm-3">
                                <select class="form-control mb15">
                                    <option value="1"> aboutus</option>
                                    <option value="2"> qiyezizhi </option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label"><span class="asterisk">*</span> 页面内容</label>
                        <div class="col-sm-6">
                            @*<textarea id="PageBody" name="PageBody" placeholder="请在此输入页面内容" class="form-control" rows="10" required>@Model.PageBody</textarea>*@
                            @Html.TextAreaFor(m => m.PageBody, new { @class = "form-control", @rows = "10", @placeholder = "请在此输入页面内容" })
                            @Html.ValidationMessageFor(m => m.PageBody, null, new { @class="help-inline"})
                        </div>
                    </div>

                    <div class="panel-footer">
                        <div class="row">
                            <div class="col-sm-6 col-sm-offset-3">
                                <button class="btn btn-primary" onclick="javascript: Save();">提交</button>&nbsp;
                                <button class="btn btn-default">取消</button>
                            </div>
                        </div>
                    </div>

                </form>
            </div>

        </div> <!-- panel -->

    </div>
</div>


<script>
    jQuery(document).ready(function () {

        // Textarea Autogrow
        jQuery('#PageBody').autogrow();

        // CKEditor
        jQuery('textarea#PageBody').ckeditor();
        jQuery('#inlineedit1, #inlineedit2').ckeditor();
        CKEDITOR.instances["PageBody"].on("instanceReady", function()   
        {   
            //set keyup event   
            this.document.on("keyup", updateTextArea);   
            //and paste event   
            this.document.on("paste", updateTextArea);   
  
        });

        // With Form Validation Wizard
        jQuery("#firstForm").validate({
            rules:{
                PageTitle:{
                    required:true,
                    isContainsSpecialChar:true
                },
                PageKeyWords:{
                    required:true,
                    isContainsSpecialChar:true
                },
                PageDescription:{
                    required:true,
                    stringContentCheck:[1,200]
                },
                PageBody:{
                    required:true
                }
            },
            messages:{
                PageTitle:{
                    required:"请输入页面标题",
                    isContainsSpecialChar:"含有中英文特殊字符"
                },
                PageKeyWords:{
                    required:"请输入页面关键字",
                    isContainsSpecialChar:"含有中英文特殊字符"
                },
                PageDescription:{
                    required:"请输入页面简介",
                    stringContentCheck:$.validator.format("请确保内容输入{0}-{1}字节以内")
                },
                PageBody:{
                    required:"请输入页面内容"
                }
            },
            highlight: function (element) {
                jQuery(element).closest('.form-group').removeClass('has-success').addClass('has-error');
            },
            success: function (element) {
                jQuery(element).closest('.form-group').removeClass('has-error');
            },
            focusInvalid: false,
            onkeyup: false,
            ignore:'',
            errorPlacement: function (error, element) {
                //alert(error.html());
                error.insertAfter($(element).parent().children().last());
            }
        });


    });

    function updateTextArea()   
    {   
        CKEDITOR.tools.setTimeout( function()   
        {    
            $("#PageBody").val(CKEDITOR.instances[$("#PageBody").attr("id")].getData());   
            $("#PageBody").trigger('keyup');  
            $("#PageBody").trigger('paste');
        }, 0);     
    } 

    // For SinglePage Add Operation , Submit Button
    function Save() {
        var $valid = jQuery('#firstForm').valid();
        if (!$valid) {
            return false;
        }
        else {
            var IsInsert = 1; // default option : insert single page model
            var SinglePageID = 0; // default option : insert single page model
            @{

                var CompanyID = 0;
                var UserModel = OperatorFactory.GetUser(User.Identity.GetUserId());
                if (UserModel != null && UserModel.CompanyID !=null&& UserModel.CompanyID.Value > 0) // UserModel.CompanyID.Value : update existing company model
                {
                    //IsInsert = 0;
                    CompanyID = UserModel.CompanyID.Value;
                }
            }

            //------------------TAB 01 : 单页信息
            var valPageTitle = $.jsparams.input("PageTitle");
            var valPageKeyWords = $.jsparams.input("PageKeyWords");
            var valPageDescription = $.jsparams.textarea("PageDescription");
            var valPageRelationFlag = $.jsparams.input("PageRelationFlag");
            var valPageBody = $.jsparams.textarea("PageBody");
            var valCompanyID = @CompanyID;

            var stringTABONE = valPageTitle + "_" + valPageKeyWords + "_" + valPageDescription + "_" +
                valPageRelationFlag + "_" + valPageBody + "_" + valCompanyID;
            alert(stringTABONE);

            var datas={ CompanyID:@CompanyID,IsInsert:IsInsert,PageTitle:valPageTitle,PageKeyWords:valPageKeyWords,
                PageDescription:valPageDescription,PageRelationFlag:valPageRelationFlag,PageBody:valPageBody};
            ComAjax("/Company/CompanySinglePageSave",datas,"单页信息");

        }
    }

</script>